package com.cskaoyan.gateway.controller.test;


import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.MyProductService;
import com.mall.shopping.constants.ShoppingRetCode;
import com.mall.shopping.dto.QueryItemByIdRequest;
import com.mall.shopping.dto.QueryItemByIdResponse;
import com.mall.user.annotation.Anonymous;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;

/**
 * 有这样的一个需求，需要根据商品id获取商品的名字，价格，数量
 * 这个请求方法是Get, queryItemById
 * 不需要登录就能直接访问
 *
 * 在这里需要去调用接口
 *
 * 接口文档类型：JSON
 *
 */
//@RestController
public class ProductController {

    @Reference(check = false)
    MyProductService productService;


    @GetMapping("queryItemById")
    @Anonymous
    public ResponseData queryItemById(Integer productId){


        QueryItemByIdRequest queryItemByIdRequest = new QueryItemByIdRequest();
        queryItemByIdRequest.setProductId(productId);

        QueryItemByIdResponse response = productService.queryItemById(queryItemByIdRequest);

        if (response.getCode().equals(ShoppingRetCode.SUCCESS.getCode())) {
            ResponseData responseData = new ResponseUtil().setData(response.getProductDTO());

            return responseData;
        }
//        ResponseData responseData = new ResponseData();

//        responseData.setCode(200);
//        responseData.setMessage("success");
//        responseData.setResult(productDTO);
//
//        return responseData;

        else {


            return new ResponseUtil().setErrorMsg(response.getMsg());
        }

    }

}
